import { ExtendsDocumentStore } from './document-detail.state.base';

export class DocumentDetailActions {
  static generateActionObject<T extends { id: string; documentStatus: number }>(
    fn: string,
    store: ExtendsDocumentStore<T>,
    payload?: any
  ) {
    const name = store['NGXS_META'].path;
    const ReflectedAction = function (data: T) {
      this.payload = data;
    };
    const obj = new ReflectedAction(payload);
    obj.__proto__.constructor.type = `[${name}] ${fn}`;
    return obj;
  }

  static ChangeToEmpty(store: ExtendsDocumentStore<any>): {} {
    return DocumentDetailActions.generateActionObject('changeToEmpty', store);
  }

  static ChangeToCreating(store: ExtendsDocumentStore<any>): {} {
    return DocumentDetailActions.generateActionObject('changeToCreating', store);
  }

  static ChangeToView(store: ExtendsDocumentStore<any>): {} {
    return DocumentDetailActions.generateActionObject('changeToView', store);
  }

  static ChangeToViewNewModel(store: ExtendsDocumentStore<any>, payload: any): any {
    return DocumentDetailActions.generateActionObject('changeToViewNewModel', store, payload);
  }

  static ChangeToEditing(store: ExtendsDocumentStore<any>): {} {
    return DocumentDetailActions.generateActionObject('changeToEditing', store);
  }

  static Save<T extends { id: string; documentStatus: number }>(
    store: ExtendsDocumentStore<T>,
    payload: any
  ): any {
    return DocumentDetailActions.generateActionObject('save', store, payload);
  }

  static Edit<T extends { id: string; documentStatus: number }>(
    store: ExtendsDocumentStore<T>,
    payload: any
  ): any {
    return DocumentDetailActions.generateActionObject('edit', store, payload);
  }

  static ChangeStatus<T extends { id: string; documentStatus: number }>(
    store: ExtendsDocumentStore<T>,
    payload: any
  ): any {
    return DocumentDetailActions.generateActionObject('changeStatus', store, payload);
  }

  static Delete<T extends { id: string; documentStatus: number }>(
    store: ExtendsDocumentStore<T>,
    payload: any
  ): any {
    return DocumentDetailActions.generateActionObject('delete', store, payload);
  }
}
